package org.easy.tencim.model.msgcontent;

import com.alibaba.fastjson.annotation.JSONField;
import org.easy.core.util.FileUtil;
import lombok.Data;

import java.util.List;

/**
 * 类描述：
 *
 * @date 2021-08-04
 */
@Data
public class TIMImageElem implements TimBaseElem {

    @Override
    public String getMsgType() {
        return "TIMImageElem";
    }

    @JSONField(name = "UUID")
    private String uuid;

    @JSONField(name = "ImageFormat")
    private Integer imageFormat;

    public Integer getImageFormat() {
        String suffixName = FileUtil.getSuffixName(imageInfo.get(0).url);
        if (suffixName.equalsIgnoreCase("jpg") ||
                suffixName.equalsIgnoreCase("jpeg"))
            return 1;

        if (suffixName.equalsIgnoreCase("git"))
            return 2;


        if (suffixName.equalsIgnoreCase("png"))
            return 3;

        if (suffixName.equalsIgnoreCase("bmp"))
            return 4;

        return 255;
    }

    @JSONField(name = "ImageInfoArray")
    private List<ImageInfo> imageInfo;


    @Data
    public static class ImageInfo {
        @JSONField(name = "Type")
        private Integer type = 1;

        @JSONField(name = "Size")
        private Long size;

        @JSONField(name = "Width")
        private Long width;

        @JSONField(name = "Height")
        private Long height;

        @JSONField(name = "URL")
        private String url;
    }

}
